package com.hy.core.util;

import java.nio.ByteBuffer;

/**
 * author: houying
 * date  : 17-6-8
 * desc  :
 */
public class ByteBufferUtils {

    public static ByteBuffer copy(ByteBuffer byteBuffer, int fromIndex, int untilIndex) {
        int size = untilIndex - fromIndex;
        byte[] dest = new byte[size];
        System.arraycopy(byteBuffer.array(), fromIndex, dest, 0, dest.length);
        return ByteBuffer.wrap(dest);
    }

    public static byte[] getBytes(ByteBuffer buffer) {
        byte[] bytes = new byte[buffer.remaining()];
        buffer.get(bytes);
        return bytes;
    }
}
